package fleditor.common
{
	import flash.events.MouseEvent;
	
	import ui.common.windowUI;

	/**
	 * 公用弹出窗口
	 * @author Devin
	 * 
	 */	
	public class WindowView extends windowUI
	{
		private var _width:Number;
		private var _height:Number;
		private var _title:String;
		
		/**
		 *  公用弹出窗口
		 * @param w 窗口宽
		 * @param h 窗口高
		 * @param t 窗口标题
		 * 
		 */		
		public function WindowView(w:Number, h:Number, t:String="")
		{
			width=w;
			height=h;
			title=t;
			
			btnClose.buttonMode=btnAlpha.buttonMode=true;
			btnClose.x=width-btnClose.width-5;
			btnAlpha.x=width-btnClose.width-btnAlpha.width-10;
			txtTitle.mouseEnabled=false;
			
			boxTC.addEventListener(MouseEvent.MOUSE_DOWN, __onTitleMouseDown);
			boxTC.addEventListener(MouseEvent.MOUSE_UP, __onTitleMouseUp);
			btnAlpha.addEventListener(MouseEvent.CLICK, __onAlphaClick);
			btnClose.addEventListener(MouseEvent.CLICK, __onCloseClick);
		}
		
		/**
		 *窗口标题 
		 * @return 
		 * 
		 */		
		public function get title():String
		{
			return _title;
		}

		/**
		 *窗口标题 
		 * @param value
		 * 
		 */		
		public function set title(value:String):void
		{
			_title = value;
			txtTitle.text=_title;
		}

		/**
		 *鼠标在标题栏按下 
		 * @param evt 鼠标事件
		 * 
		 */		
		private function __onTitleMouseDown(evt:MouseEvent):void
		{
			this.startDrag();//拖动窗口开始
		}
		
		/**
		 *鼠标在标题栏弹起 
		 * @param evt 鼠标事件
		 * 
		 */	
		private function __onTitleMouseUp(evt:MouseEvent):void
		{
			this.stopDrag();//拖动窗口结束
		}
		
		/**
		 *透明操作 
		 * @param evt 鼠标事件
		 * 
		 */		
		private function __onAlphaClick(evt:MouseEvent):void
		{
			alpha=alpha<=0.5 ? 1 : 0.5;
		}
		
		/**
		 *关闭操作 
		 * @param evt 鼠标事件
		 * 
		 */	
		private function __onCloseClick(evt:MouseEvent):void
		{
			dispose();
		}		

		/**
		 *窗口宽度 
		 * @return 
		 * 
		 */		
		override public function get width():Number
		{
			return _width;
		}

		/**
		 *窗口宽度 
		 * @return 
		 * 
		 */		
		override public function set width(value:Number):void
		{
			if(_width==value) return;
			_width = value;
			
			boxTL.x=0;
			boxTC.x=boxTL.width;
			boxTC.width=_width-boxTL.width-boxTR.width;
			boxTR.x=_width-boxTR.width;
			
			boxCL.x=0;
			boxCC.x=boxCL.width;
			boxCC.width=_width-boxCL.width-boxCR.width;
			boxCR.x=_width-boxCR.width;
			
			boxBL.x=0;
			boxBC.x=boxBL.width;
			boxBC.width=_width-boxBL.width-boxBR.width;
			boxBR.x=_width-boxBR.width;
		}

		/**
		 *窗口高度 
		 * @return 
		 * 
		 */		
		override public function get height():Number
		{
			return _height;
		}

		/**
		 *窗口高度 
		 * @return 
		 * 
		 */		
		override public function set height(value:Number):void
		{
			if(_height==value) return;
			_height = value;
			
			boxTL.y=0;
			boxTC.y=0;
			boxTR.y=0;
			
			boxCL.y=boxTL.height;
			boxCL.height=_height-boxCL.height-boxBL.height;
			boxCC.y=boxTC.height;
			boxCC.height=_height-boxTC.height-boxBC.height;
			boxCR.y=boxTR.height;
			boxCR.height=_height-boxTR.height-boxBR.height;
			
			boxBL.y=_height-boxBL.height;
			boxBC.y=_height-boxBC.height;
			boxBR.y=_height-boxBR.height;
		}
		
		/**
		 * 资源释放 
		 * 
		 */		
		public function dispose():void
		{
			boxTC.removeEventListener(MouseEvent.MOUSE_DOWN, __onTitleMouseDown);
			boxTC.removeEventListener(MouseEvent.MOUSE_UP, __onTitleMouseUp);
			btnAlpha.removeEventListener(MouseEvent.CLICK, __onAlphaClick);
			btnClose.removeEventListener(MouseEvent.CLICK, __onCloseClick);
			
			if(parent) parent.removeChild(this);
		}
	}
}